<template>
    <div class="bnk">
        <h2 class="text-white" style="text-align: center;font-weight: bold;">贵州省固废系统“处置单位“数据请求测试</h2>
        <br/>
        <a-row  >
            <a-col :sm="24" :md="14" style="margin-right: 10px;" >
                <a-card title="用户登录测试" >
                    <a-form :form="form" :label-col="{ span: 5 }" :wrapper-col="{ span: 12 }" @submit="handleLogin">
                        <a-form-item label="登录账户">
                            <a-input v-decorator="['loginName', { rules: [{ required: true, message: '请输入账户名称!' }] }]"/>
                        </a-form-item>
                        <a-form-item label="登录密码">
                            <a-input v-decorator="['password', { rules: [{ required: true, message: '请输入登录密码!' }] }]"/>
                        </a-form-item>
                        <a-form-item :wrapper-col="{ span: 12, offset: 5 }">
                            <a-button type="primary" html-type="submit">
                                立即登录
                            </a-button>
                        </a-form-item>
                    </a-form>
                </a-card>
                <br/>
                <a-card title="添加”处置机构“车辆" >
                    <a-form :form="form1" :label-col="{ span: 5 }" :wrapper-col="{ span: 12 }" @submit="handleAddCar">
                        <a-form-item label="驾驶员名字">
                            <a-input v-decorator="['carName', { rules: [{ required: true, message: '不能为空!' }] }]"/>
                        </a-form-item>
                        <a-form-item label="车牌号">
                            <a-input v-decorator="['carNumber', { rules: [{ required: true, message: '不能为空!' }] }]"/>
                        </a-form-item>
                        <a-form-item label="状态">
                            <a-input v-decorator="['status', { rules: [{ required: true, message: '不能为空!' }] }]"/>
                        </a-form-item>
                        <a-form-item :wrapper-col="{ span: 12, offset: 5 }">
                            <a-button type="primary" html-type="submit">
                                立即添加
                            </a-button>
                        </a-form-item>
                    </a-form>
                </a-card>
                <br/>
                <a-card title="根据废物编号查询废物信息">
                    <a-form :form="form2" :label-col="{ span: 5 }" :wrapper-col="{ span: 12 }" @submit="getWasteData">
                        <a-form-item label="废物编号">
                            <a-input v-decorator="['wasteNumber', { rules: [{ required: true, message: '不能为空!' }] }]"/>
                        </a-form-item>
                        <a-form-item :wrapper-col="{ span: 12, offset: 5 }">
                            <a-button type="primary" html-type="submit">立即查询</a-button>
                        </a-form-item>
                    </a-form>
                </a-card>
                <br/>
                <a-card title="根据医院ID和废物编号获取废物列表">
                    <a-form :form="form3" :label-col="{ span: 5 }" :wrapper-col="{ span: 12 }" @submit="getWasteDataByID">
                        <a-form-item label="page">
                            <a-input v-decorator="['page', { rules: [{ required: true, message: '不能为空!' }] }]"/>
                        </a-form-item>
                        <a-form-item label="医院ID">
                            <a-input v-decorator="['hospitalInfo', { rules: [{ required: true, message: '不能为空!' }] }]"/>
                        </a-form-item>
                        <a-form-item label="废物编号">
                            <a-input v-decorator="['findNumber']"/>
                        </a-form-item>
                        <a-form-item :wrapper-col="{ span: 12, offset: 5 }">
                            <a-button type="primary" html-type="submit">立即查询</a-button>
                        </a-form-item>
                    </a-form>
                </a-card>
                <br/>
                <a-card title="处置单位收运员收运医废">
                    <a-form :form="form4" :label-col="{ span: 5 }" :wrapper-col="{ span: 12 }" @submit="handleAddTransport">
                        <a-form-item label="医院ID">
                            <a-input v-decorator="['hospitalId', { rules: [{ required: true, message: '不能为空!' }] }]"/>
                        </a-form-item>
                        <a-form-item label="车牌号">
                            <a-input v-decorator="['carId', { rules: [{ required: true, message: '不能为空!' }] }]"/>
                        </a-form-item>
                        <a-form-item label="医院签字">
                            <a-input v-decorator="['hospitalFile', { rules: [{ required: true, message: '不能为空!' }] }]"/>
                        </a-form-item>
                        <a-form-item label="交接签字">
                            <a-input v-decorator="['transportFile', { rules: [{ required: true, message: '不能为空!' }] }]"/>
                        </a-form-item>
                        <a-form-item :wrapper-col="{ span: 12, offset: 5 }">
                            <a-button type="primary" html-type="submit">提交收运数据信息</a-button>
                        </a-form-item>
                    </a-form>
                </a-card>
                <br/>
                <a-card title="处置单位医疗垃圾“入库”">
                    <a-form :form="form5" :label-col="{ span: 5 }" :wrapper-col="{ span: 12 }" @submit="handlePostSignUrl">
                        <a-form-item label="车辆ID">
                            <a-input v-decorator="['carId', { rules: [{ required: true, message: '不能为空!' }] }]"/>
                        </a-form-item>
                        <a-form-item label="签字">
                            <a-input v-decorator="['filePath', { rules: [{ required: true, message: '不能为空!' }] }]"/>
                        </a-form-item>
                        <a-form-item :wrapper-col="{ span: 12, offset: 5 }">
                            <a-button type="primary" html-type="submit">提交废物"入库"</a-button>
                        </a-form-item>
                    </a-form>
                </a-card>

            </a-col>

            <a-col :sm="24" :md="9">
                <a-card title="数据信息查询">
                    <a-form-item label="处置单位编号">
                        <a-input v-model="disposalInfo" />
                    </a-form-item>
                    <a-button type="primary" style="margin-bottom: 20px;" @click="getCarListData" >
                        获取车辆信息
                    </a-button>
                    <a-list size="small" bordered :data-source="dataSource">
                        <a-list-item slot="renderItem" slot-scope="item, index">
                            <span class="text-white" >{{`${item.carName} - ${item.carNumber} - ${item.id}`}}</span>
                        </a-list-item>
                    </a-list>
                </a-card>
                <br/>
                <a-card title="登陆结果">
                    <div class="text-white" style="word-break: break-word;" >{{loginText}}</div>
                </a-card>
                <br/>
                <a-card title="操作结果" >
                    <div class="text-white" style="word-break: break-word;" >{{text}}</div>
                </a-card>
            </a-col>
        </a-row>
    </div>
</template>

<script>
    import { getAction, postAction } from '../../api/manage'

    export default {
        data() {
            return {
                formLayout: 'horizontal',
                form: this.$form.createForm(this, { name: 'coordinated' }),
                form1: this.$form.createForm(this, { name: 'coordinated' }),
                form2: this.$form.createForm(this, { name: 'coordinated' }),
                form3: this.$form.createForm(this, { name: 'coordinated' }),
                form4: this.$form.createForm(this, { name: 'coordinated' }),
                form5: this.$form.createForm(this, { name: 'coordinated' }),

                dataSource : [],
                activeKey: [],

                wasteData : [],

                loginText: '',
                text: '',

                url: {
                    login: '/hc/test/loginDispose',
                    getCarList: '/hc/test/getCarList',
                    getWasteURL: '/hc/test/getWaste',
                    getWasteListByTypeURL: '/hc/test/getWasteListByType',

                    addCar: '/hc/test/addCar',
                    addTransportUrl: '/hc/test/addTransport',
                    postSignUrl: '/hc/test/postSign',
                },
                disposalInfo : '0b7s7t5J164r'
            }
        },
        mounted() {
            this.form.setFieldsValue({
                loginName: '13608516633',
                password: 'zj5201314',
            })
            this.form1.setFieldsValue({
                status: 1
            })
            this.form2.setFieldsValue({
                wasteNumber: '202107291731068'
            })
            this.form3.setFieldsValue({
                page: 0,
                hospitalInfo: "5snR3oQ31p7j",
                // findNumber: '202107291731068'
            })
            this.form4.setFieldsValue({
                hospitalId:'5snR3oQ31p7j',
                carId:'VykX3SHuevznYydjhsG1bK',
                hospitalFile:'C:\\Users\\Administrator\\Desktop\\工作资料\\16269246908400_1626924751053.jpg',
                transportFile:'C:\\Users\\Administrator\\Desktop\\工作资料\\16269246908400_1626924751053.jpg',
            })
            this.form5.setFieldsValue({
                carId:'VykX3SHuevznYydjhsG1bK',
                filePath:'C:\\Users\\Administrator\\Desktop\\工作资料\\16269246908400_1626924751053.jpg',
            })
        },
        methods: {
            getCarListData : async function(){
                let params = {
                    disposalInfo : this.disposalInfo
                };
                let res = await getAction(this.url.getCarList,params);
                this.dataSource = res || [];
                this.dataSource.forEach((item,index) => {
                    this.activeKey.push(`${index}`)
                })
                this.text = JSON.stringify(res)
            },
            // 用户登录
            handleLogin(e) {
                e.preventDefault()
                let _this = this
                this.form.validateFields(async (err, values) => {
                    if (!err) {
                        let params = {
                            loginName : values.loginName,
                            password : values.password,
                        };
                        let res = await getAction(_this.url.login, params)
                        _this.loginText = JSON.stringify(res)
                    }
                })
            },
            getWasteData : async function(e){
                e.preventDefault()
                let _this = this
                this.form2.validateFields(async (err, values) => {
                    if (!err) {
                        values['disposalInfo'] = _this.disposalInfo;
                        let res = await getAction(_this.url.getWasteURL,values);
                        _this.wasteData = res || [];
                        _this.text = JSON.stringify(res)
                    }
                })
            },
            getWasteDataByID : async function(e){
                e.preventDefault()
                let _this = this
                this.form3.validateFields(async (err, values) => {
                    if (!err) {
                        values['disposalInfo'] = _this.disposalInfo;
                        let res = await getAction(_this.url.getWasteListByTypeURL,values);
                        _this.wasteData = res || [];
                        _this.text = JSON.stringify(res)
                    }
                })
            },
            handleAddCar(e) {
                e.preventDefault()
                let _this = this
                this.form1.validateFields(async (err, values) => {
                    if (!err) {
                        values['disposalInfo'] = _this.disposalInfo;
                        let res = await getAction(_this.url.addCar, values)
                        _this.text = JSON.stringify(res)
                    }
                })
            },
            handleAddTransport(e) {
                e.preventDefault()
                let _this = this
                this.form4.validateFields(async (err, values) => {
                    if (!err) {
                        values['disposalInfo'] = _this.disposalInfo;
                        let res = await postAction(_this.url.addTransportUrl, values)
                        _this.text = JSON.stringify(res)
                    }
                })
            },
            handlePostSignUrl(e) {
                e.preventDefault()
                let _this = this
                this.form5.validateFields(async (err, values) => {
                    if (!err) {
                        values['disposalInfo'] = _this.disposalInfo;
                        let res = await postAction(_this.url.postSignUrl, values)
                        _this.text = JSON.stringify(res)
                    }
                })
            },
        }
    }
</script>

<style lang="less" scoped>
    .bnk {
        padding: 20px;
    }
</style>
